import $http from '../utils/http.js'
import router from '../routers/router.js'
import { Notification } from 'atelement'
const jump = '/blankPage/jump'
const getPath = function (data) {
  if (data.path != null) {
    return data.path
  } else {
    return getPath(data.children[0])
  }
}
export default{
  actions: {
    [jump] (state, code) {
      $http.post('/api/auth/sso', code).then(function ({ status, data, msg }) {
        if (status === 'success') {
          router.push(getPath(data.menu[0]))
        } else {
          Notification.error({
            title: msg
          })
        }
      }).catch(function (err) {
        console.log(err)
      })
    }
  }
}
